﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masterpages/Main.master" AutoEventWireup="true" CodeFile="QuestionAnswer.aspx.cs" Inherits="User_Shares_QuestionAnswer" %>

<%@ Register src="../../Controls/ContentHolder/Holder1.ascx" tagname="Holder1" tagprefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <uc1:Holder1 ID="Holder11" runat="server" Title="پرسش و پاسخ">
  <ContentTemplate>
    <table class="style1" dir="rtl" align="center">
        <tr>
            <td class="style2">
                <asp:MultiView ID="MultiView1" runat="server">
                 <asp:View ID="View1" runat="server">
   <table class="style1" dir="ltr">
                        <tr>
                            
                            <td class="style2">
                                <asp:TextBox ID="TxtQuestion" runat="server" Height="62px" TextMode="MultiLine" 
                                    Width="486px"></asp:TextBox>
                            </td>
                            <td>
                                <asp:Label ID="Label1" runat="server" CssClass="MainObject" Text="طرح سوال"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="style2">
                                <asp:Button ID="BtnSendQuestion" runat="server" CssClass="MainObject" 
                                    onclick="Button1_Click" Text="ارسال سوال" />
                            </td>
                            <td>
                                <asp:Label ID="LblStatus" runat="server"></asp:Label>
                            </td>
                        </tr>
                    </table>
                            </asp:View>
                    <asp:View ID="View2" runat="server">
 <asp:Panel ID="PanelGridQuestion" runat="server">
                         
                        <table class="style
                           
                            1">
                            <tr>
                                <td align="center">
                                    
                                    <asp:Label ID="Label2" runat="server" CssClass="MainObject" Text="لیست سوالات"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:GridView ID="GridviewQuestions" runat="server" AutoGenerateColumns="False" 
                                        CellPadding="4" CssClass="MainObject" DataSourceID="SqlDataSourceQuestions" 
                                        EnableModelValidation="True" GridLines="None" DataKeyNames="ID" 
                                        onrowcommand="GridviewQuestions_RowCommand" AllowPaging="True" 
                                        onrowdatabound="GridviewQuestions_RowDataBound">
                                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                        <Columns>
                                            <asp:ButtonField CommandName="Select" Text="ثبت پاسخ"  ItemStyle-Width="100" />
                                            <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" 
                                                SortExpression="ID" Visible="False" ItemStyle-Width="100"  />
                                            <asp:BoundField DataField="Question" HeaderText="سوال" 
                                                SortExpression="Question"  ItemStyle-Width="100" >
                                            <ItemStyle  />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="UserName" HeaderText="پرسش کننده" 
                                                SortExpression="UserName"  ItemStyle-Width="100" >
                                            <ItemStyle/>
                                            </asp:BoundField>
                                            <asp:BoundField DataField="Date" HeaderText="تاریخ" SortExpression="Date"  ItemStyle-Width="100" >
                                            <ItemStyle  />
                                            </asp:BoundField>
                                        </Columns>
                                        <EditRowStyle BackColor="#999999" />
                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                    </asp:GridView>
                                    <asp:SqlDataSource ID="SqlDataSourceQuestions" runat="server" 
                                        ProviderName="System.Data.SqlClient" 
                                        SelectCommand="SELECT * FROM [TblQuestions]" 
                                        ConflictDetection="CompareAllValues" 
                                        DeleteCommand="DELETE FROM [TblQuestions] WHERE [ID] = @original_ID AND (([Question] = @original_Question) OR ([Question] IS NULL AND @original_Question IS NULL)) AND (([UserName] = @original_UserName) OR ([UserName] IS NULL AND @original_UserName IS NULL)) AND (([Date] = @original_Date) OR ([Date] IS NULL AND @original_Date IS NULL))" 
                                        InsertCommand="INSERT INTO [TblQuestions] ([ID], [Question], [UserName], [Date]) VALUES (@ID, @Question, @UserName, @Date)" 
                                        OldValuesParameterFormatString="original_{0}" 
                                        UpdateCommand="UPDATE [TblQuestions] SET [Question] = @Question, [UserName] = @UserName, [Date] = @Date WHERE [ID] = @original_ID AND (([Question] = @original_Question) OR ([Question] IS NULL AND @original_Question IS NULL)) AND (([UserName] = @original_UserName) OR ([UserName] IS NULL AND @original_UserName IS NULL)) AND (([Date] = @original_Date) OR ([Date] IS NULL AND @original_Date IS NULL))">
                                        <DeleteParameters>
                                            <asp:Parameter Name="original_ID" Type="Object" />
                                            <asp:Parameter Name="original_Question" Type="String" />
                                            <asp:Parameter Name="original_UserName" Type="String" />
                                            <asp:Parameter Name="original_Date" Type="DateTime" />
                                        </DeleteParameters>
                                        <InsertParameters>
                                            <asp:Parameter Name="ID" Type="Object" />
                                            <asp:Parameter Name="Question" Type="String" />
                                            <asp:Parameter Name="UserName" Type="String" />
                                            <asp:Parameter Name="Date" Type="DateTime" />
                                        </InsertParameters>
                                        <UpdateParameters>
                                            <asp:Parameter Name="Question" Type="String" />
                                            <asp:Parameter Name="UserName" Type="String" />
                                            <asp:Parameter Name="Date" Type="DateTime" />
                                            <asp:Parameter Name="original_ID" Type="Object" />
                                            <asp:Parameter Name="original_Question" Type="String" />
                                            <asp:Parameter Name="original_UserName" Type="String" />
                                            <asp:Parameter Name="original_Date" Type="DateTime" />
                                        </UpdateParameters>
                                    </asp:SqlDataSource>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    &nbsp;</td>
                            </tr>
                        </table>
                          </asp:Panel>
                         <asp:Panel ID="PanelAnswer" runat="server" Visible="False">
                                    <table class="style1">
                                        <tr>
                                            <td>
                                                <asp:Label ID="Label4" runat="server" CssClass="MainObject" Text="سوال"></asp:Label>
                                            </td>
                                            <td colspan="2">
                                                <asp:Label ID="LblQuestion" runat="server" CssClass="MainObject"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                <asp:Label ID="Label3" runat="server" CssClass="MainObject" Text="پاسخ"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="TxtAnswer" runat="server" Height="84px" TextMode="MultiLine" 
                                                    Width="289px"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                &nbsp;</td>
                                            <td>
                                                <asp:Button ID="BtnSendAnswer" runat="server" CssClass="MainObject" 
                                                    Text="ارسال پاسخ" onclick="BtnSendAnswer_Click" />
                                                <asp:Button ID="Button1" runat="server" CssClass="MainObject" 
                                                    onclick="Button1_Click1" Text="انصراف" Width="100px" />
                                            </td>
                                        </tr>
                                    </table>
                                    </asp:Panel>
                                    
                    </asp:View>
                    <asp:View ID="View3" runat="server">
                        <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSourceView" 
                            EnableModelValidation="True" onitemdatabound="ListView1_ItemDataBound" 
                            EnableTheming="True" ondatabound="ListView1_DataBound">
                            <AlternatingItemTemplate>
                                <li class="MainObject" style="">سوال:
                                    <asp:Label ID="سوالLabel" runat="server" Text='<%# Eval( "سوال" ) %>' />
                                    <br />
                                    پرسش کننده:
                                    <asp:Label ID="پرسش_کنندهLabel" runat="server" 
                                        Text='<%# Eval( "[پرسش کننده]" ) %>' />
                                    <br />
                                    پاسخ:
                                    <asp:Label ID="پاسخLabel" runat="server" Text='<%# Eval( "پاسخ" ) %>' />
                                    <br />
                                    پاسخ دهنده:
                                    <asp:Label ID="پاسخ_دهندهLabel" runat="server" 
                                        Text='<%# Eval( "[پاسخ دهنده]" ) %>' />
                                    <br />
                                    تاریخ طرح سوال:
                                    <asp:Label ID="تاریخ_طرح_سوالLabel" runat="server" 
                                        Text='<%# PersianDateControls.Convertor.ToPersianDate(Convert.ToDateTime( Eval("[تاریخ طرح سوال]")) ) + " " + Convert.ToDateTime( Eval("[تاریخ طرح سوال]") ).ToShortTimeString().Replace( "AM" , "صبح").Replace( "PM" , "عصر" )   %>' />
                                    <br />
                                    تاریخ پاسخ:
                                    <asp:Label ID="تاریخ_پاسخLabel" runat="server" 
                                        Text='<%# PersianDateControls.Convertor.ToPersianDate(Convert.ToDateTime( Eval("[تاریخ پاسخ]")) ) + " " + Convert.ToDateTime(  Eval("[تاریخ پاسخ]")).ToShortTimeString().Replace( "AM" , "صبح").Replace( "PM" , "عصر" )  %>' />
                                    <br />
                                  
                                </li>
                            </AlternatingItemTemplate>
                            <EditItemTemplate>
                                <li class="MainObject" style="">سوال:
                                    <asp:TextBox ID="سوالTextBox" runat="server" Text='<%# Bind( "سوال" ) %>' />
                                    <br />
                                    پرسش کننده:
                                    <asp:TextBox ID="پرسش_کنندهTextBox" runat="server" 
                                        Text='<%# Bind( "[پرسش کننده]" ) %>' />
                                    <br />
                                    پاسخ:
                                    <asp:TextBox ID="پاسخTextBox" runat="server" Text='<%# Bind( "پاسخ" ) %>' />
                                    <br />
                                    پاسخ دهنده:
                                    <asp:TextBox ID="پاسخ_دهندهTextBox" runat="server" 
                                        Text='<%# Bind( "[پاسخ دهنده]" ) %>' />
                                    <br />
                                     تاریخ طرح سوال:
                                    <asp:Label ID="تاریخ_طرح_سوالLabel" runat="server" 
                                        Text='<%# PersianDateControls.Convertor.ToPersianDate(Convert.ToDateTime( Eval("[تاریخ طرح سوال]")) ) + " " + Convert.ToDateTime( Eval("[تاریخ طرح سوال]") ).ToShortTimeString().Replace( "AM" , "صبح").Replace( "PM" , "عصر" )   %>' />
                                    <br />
                                    تاریخ پاسخ:
                                    <asp:Label ID="تاریخ_پاسخLabel" runat="server" 
                                        Text='<%# PersianDateControls.Convertor.ToPersianDate(Convert.ToDateTime( Eval("[تاریخ پاسخ]")) ) + " " + Convert.ToDateTime(  Eval("[تاریخ پاسخ]")).ToShortTimeString().Replace( "AM" , "صبح").Replace( "PM" , "عصر" )  %>' />
                                    <br />
                                  
                                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                                        Text="Update" />
                                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                                        Text="Cancel" />
                                </li>
                            </EditItemTemplate>
                            <EmptyDataTemplate>
                              هیچ سوالی یافت نشد.
                            </EmptyDataTemplate>
                            <InsertItemTemplate>
                                <li class="MainObject" style="">سوال:
                                    <asp:TextBox ID="سوالTextBox" runat="server" Text='<%# Bind( "سوال" ) %>' />
                                    <br />
                                    پرسش کننده:
                                    <asp:TextBox ID="پرسش_کنندهTextBox" runat="server" 
                                        Text='<%# Bind( "[پرسش کننده]" ) %>' />
                                    <br />
                                    پاسخ:
                                    <asp:TextBox ID="پاسخTextBox" runat="server" Text='<%# Bind( "پاسخ" ) %>' />
                                    <br />
                                    پاسخ دهنده:
                                    <asp:TextBox ID="پاسخ_دهندهTextBox" runat="server" 
                                        Text='<%# Bind( "[پاسخ دهنده]" ) %>' />
                                    <br />
                                    تاریخ طرح سوال:
                                    <asp:Label ID="تاریخ_طرح_سوالLabel" runat="server" 
                                        Text='<%# PersianDateControls.Convertor.ToPersianDate(Convert.ToDateTime( Eval("[تاریخ طرح سوال]")) ) + " " + Convert.ToDateTime( Eval("[تاریخ طرح سوال]") ).ToShortTimeString().Replace( "AM" , "صبح").Replace( "PM" , "عصر" )   %>' />
                                    <br />
                                    تاریخ پاسخ:
                                    <asp:Label ID="تاریخ_پاسخLabel" runat="server" 
                                        Text='<%# PersianDateControls.Convertor.ToPersianDate(Convert.ToDateTime( Eval("[تاریخ پاسخ]")) ) + " " + Convert.ToDateTime(  Eval("[تاریخ پاسخ]")).ToShortTimeString().Replace( "AM" , "صبح").Replace( "PM" , "عصر" )  %>' />
                                    <br />
                                  
                                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                                        Text="Insert" />
                                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                                        Text="Clear" />
                                </li>
                            </InsertItemTemplate>
                            <ItemSeparatorTemplate>
                                <br />
                            </ItemSeparatorTemplate>
                            <ItemTemplate>
                                <li style="" class="MainObject">سوال:
                                    <asp:Label ID="سوالLabel" runat="server" Text='<%# Eval( "سوال" ) %>' />
                                    <br />
                                    پرسش کننده:
                                    <asp:Label ID="پرسش_کنندهLabel" runat="server" 
                                        Text='<%# Eval( "[پرسش کننده]" ) %>' />
                                    <br />
                                    پاسخ:
                                    <asp:Label ID="پاسخLabel" runat="server" Text='<%# Eval( "پاسخ" ) %>' />
                                    <br />
                                    پاسخ دهنده:
                                    <asp:Label ID="پاسخ_دهندهLabel" runat="server" 
                                        Text='<%# Eval( "[پاسخ دهنده]" ) %>' />
                                    <br />
                                    تاریخ طرح سوال:
                                    <asp:Label ID="تاریخ_طرح_سوالLabel" runat="server" 
                                        Text='<%# PersianDateControls.Convertor.ToPersianDate(Convert.ToDateTime( Eval("[تاریخ طرح سوال]")) ) + " " + Convert.ToDateTime( Eval("[تاریخ طرح سوال]") ).ToShortTimeString().Replace( "AM" , "صبح").Replace( "PM" , "عصر" )   %>' />
                                    <br />
                                    تاریخ پاسخ:
                                    <asp:Label ID="تاریخ_پاسخLabel" runat="server" 
                                        Text='<%# PersianDateControls.Convertor.ToPersianDate(Convert.ToDateTime( Eval("[تاریخ پاسخ]")) ) + " " + Convert.ToDateTime(  Eval("[تاریخ پاسخ]")).ToShortTimeString().Replace( "AM" , "صبح").Replace( "PM" , "عصر" )  %>' />
                                    <br />
                                 
                                </li>
                            </ItemTemplate>
                            <LayoutTemplate>
                                <ul ID="itemPlaceholderContainer" runat="server" 
                                    style="">
                                    <li runat="server" id="itemPlaceholder" />
                                </ul>
                                <div style="">
                                    <asp:DataPager ID="DataPager1" runat="server">
                                        <Fields>
                                            <asp:NextPreviousPagerField ButtonType="Button" 
                                                ShowFirstPageButton="True" ShowNextPageButton="False" 
                                                ShowPreviousPageButton="False" FirstPageText="اولین" />
                                            <asp:NumericPagerField />
                                            <asp:NextPreviousPagerField ButtonType="Button" 
                                                ShowLastPageButton="True" ShowNextPageButton="False" 
                                                ShowPreviousPageButton="False" FirstPageText="اولین" LastPageText="آخرین" NextPageText="بعدی" PreviousPageText="قبلی" />
                                        </Fields>
                                    </asp:DataPager>
                                </div>
                            </LayoutTemplate>
                            <SelectedItemTemplate>
                                <li class="MainObject" style="">سوال:
                                    <asp:Label ID="سوالLabel" runat="server" Text='<%# Eval( "سوال" ) %>' />
                                    <br />
                                    پرسش کننده:
                                    <asp:Label ID="پرسش_کنندهLabel" runat="server" 
                                        Text='<%# Eval( "[پرسش کننده]" ) %>' />
                                    <br />
                                    پاسخ:
                                    <asp:Label ID="پاسخLabel" runat="server" Text='<%# Eval( "پاسخ" ) %>' />
                                    <br />
                                    پاسخ دهنده:
                                    <asp:Label ID="پاسخ_دهندهLabel" runat="server" 
                                        Text='<%# Eval( "[پاسخ دهنده]" ) %>' />
                                    <br />
                                    تاریخ طرح سوال:
                                    <asp:Label ID="تاریخ_طرح_سوالLabel" runat="server" 
                                        Text='<%# Eval("[تاریخ طرح سوال]") %>' />
                                    <br />
                                    تاریخ پاسخ:
                                    <asp:Label ID="تاریخ_پاسخLabel" runat="server" 
                                        Text='<%# Eval("[تاریخ پاسخ]") %>' />
                                    <br />
                                  
                                </li>
                            </SelectedItemTemplate>
                            
                        </asp:ListView>
                        <asp:SqlDataSource ID="SqlDataSourceView" runat="server" 
                            ProviderName="System.Data.SqlClient" 
                            
                            
                            SelectCommand="SELECT TblQuestions.Question AS سوال, TblQuestions.UserName AS [پرسش کننده], TblAnswers.Answer AS پاسخ, TblAnswers.UserName AS [پاسخ دهنده], TblQuestions.Date AS [تاریخ طرح سوال], TblAnswers.Date AS [تاریخ پاسخ] FROM TblAnswers INNER JOIN TblQuestions ON TblAnswers.QuestionID = TblQuestions.ID ORDER BY TblAnswers.Date,TblQuestions.Date DESC">
                        </asp:SqlDataSource>
                        <%--<asp:DataList ID="DataList1" runat="server" BackColor="#CCCCCC" 
                            BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" 
                            CellSpacing="2" DataSourceID="SqlDataSourceView" ForeColor="Black" 
                            GridLines="Both" RepeatColumns="2" 
                            RepeatDirection="Horizontal">
                            <FooterStyle BackColor="#CCCCCC" />
                            <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                            <ItemStyle BackColor="White" />
                            <ItemTemplate>
                                سوال:
                                <asp:Label ID="سوالLabel" runat="server" CssClass="MainObject" 
                                    Text='<%# Eval("سوال") %>' />
                                <br />
                                پرسش کننده:
                                <asp:Label ID="پرسش_کنندهLabel" runat="server" CssClass="MainObject" 
                                    Text='<%# Eval("[پرسش کننده]") %>' />
                                <br />
                                پاسخ:
                                <asp:Label ID="پاسخLabel" runat="server" CssClass="MainObject" 
                                    Text='<%# Eval("پاسخ") %>' />
                                <br />
                                پاسخ دهنده:
                                <asp:Label ID="پاسخ_دهندهLabel" runat="server" CssClass="MainObject" 
                                    Text='<%# Eval("[پاسخ دهنده]") %>' />
                                <br />
                                تاریخ طرح سوال:
                                <asp:Label ID="تاریخ_طرح_سوالLabel" runat="server" CssClass="MainObject" 
                                    Text='<%# Eval("[تاریخ طرح سوال]") %>' />
                                <br />
                                تاریخ دریافت پاسخ:
                                <asp:Label ID="تاریخ_پاسخLabel" runat="server" CssClass="MainObject" 
                                    Text='<%# Eval("[تاریخ پاسخ]") %>' />
                                <br />
                                <br />
                            </ItemTemplate>
                            <SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                        </asp:DataList>--%>
                        </asp:View>
                        
                <asp:View ID="View4" runat="server">

                    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSourceEdit" 
                        EnableModelValidation="True" AutoGenerateColumns="False" 
                        CssClass="MainObject" DataKeyNames="ID" >
                        <Columns>
                            <asp:CommandField ShowDeleteButton="True"  DeleteText="حذف" ItemStyle-Width="100"  />
                            <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" 
                                SortExpression="ID" Visible="False"  ItemStyle-Width="100" />
                            <asp:BoundField DataField="Question" HeaderText="سوال" 
                                SortExpression="Question"  ItemStyle-Width="100" />
                            <asp:BoundField DataField="UserName" HeaderText="پرسش کننده" 
                                SortExpression="UserName" ItemStyle-Width="100"  />
                            <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" 
                                Visible="False" ItemStyle-Width="100"  />
                        </Columns>
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSourceEdit" runat="server" 
                        DeleteCommand="DELETE FROM [TblQuestions] WHERE [ID] = @original_ID" 
                        InsertCommand="INSERT INTO [TblQuestions] ([ID], [Question], [UserName], [Date]) VALUES (@ID, @Question, @UserName, @Date)" 
                        OldValuesParameterFormatString="original_{0}" 
                        ProviderName="System.Data.SqlClient" 
                        SelectCommand="SELECT * FROM [TblQuestions]" 
                        
                        UpdateCommand="UPDATE [TblQuestions] SET [Question] = @Question, [UserName] = @UserName, [Date] = @Date WHERE [ID] = @original_ID">
                        <DeleteParameters>
                            <asp:Parameter Name="original_ID" Type="Object" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:Parameter Name="ID" Type="Object" />
                            <asp:Parameter Name="Question" Type="String" />
                            <asp:Parameter Name="UserName" Type="String" />
                            <asp:Parameter Name="Date" Type="DateTime" />
                        </InsertParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="Question" Type="String" />
                            <asp:Parameter Name="UserName" Type="String" />
                            <asp:Parameter Name="Date" Type="DateTime" />
                            <asp:Parameter Name="original_ID" Type="Object" />
                        </UpdateParameters>
                    </asp:SqlDataSource>

                </asp:View>
                </asp:MultiView>
            </td>
        </tr>
        <tr>
            <td class="style2">
                
            </td>
        </tr>
        </table>
    <%--  تاریخ طرح سوال:
                                    <asp:TextBox ID="تاریخ_طرح_سوالTextBox" runat="server" 
                                        Text='<%# Bind("[تاریخ طرح سوال]") %>' />
                                    <br />
                                    تاریخ پاسخ:
                                    <asp:TextBox ID="تاریخ_پاسخTextBox" runat="server" 
                                        Text='<%# Bind("[تاریخ پاسخ]") %>' />
                                    <br />--%>
  </ContentTemplate></uc1:Holder1>
</asp:Content>

